<template>
 <div>

    <el-table
      :data="menulist"
      style="width: 100%;"
      row-key="id"
      border
      default-expand-all
      :tree-props="{ children: 'children'}"
    >
      <el-table-column prop="id" label="菜单编号" width="160">
      </el-table-column>
      <el-table-column prop="title" label="菜单名称" width="160">
      </el-table-column>
      <el-table-column prop="pid" label="上级菜单"> </el-table-column>
      <el-table-column prop="icon" label="菜单图标"> </el-table-column>
      <el-table-column prop="url" label="菜单地址"> </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="item">
          <div>
            <el-tag v-if="item.row.status==1" type="success">启动</el-tag>
            <el-tag v-else type="danger">禁用</el-tag>
          </div>
        </template>
         </el-table-column>
      <el-table-column label="操作" width="180">
        <template slot-scope="item">
          <div>
            <el-button
              type="danger"
              icon="el-icon-delete"
              @click="del(item.row.id)"
              circle
            ></el-button>
            <el-button type="primary" icon="el-icon-edit" @click="edit(item.row.id)" circle></el-button>
            <el-button icon="el-icon-search" circle></el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
 </div>
</template>

<script>
import {mapGetters,mapActions} from 'vuex'
import { menuList, menuDel } from "../../util/request/api";
export default {
  data() {
    return {
      info:{
        isshow: false,
        isadd:true,
      },
      
      tableData: [],
    };
  },
   computed:{
    ...mapGetters({
      menulist:'menu/getMenuList'
    })
  },
mounted() {
    //组件一加载就获取菜单列表
    this.getMenulist()
  },
  methods: {
     ...mapActions({
      getMenulist:'menu/getMenuAction'
    }),
    handleSelect(key, keyPath) {
      console.log(keyPath[0]);
    },
    cancel(e) {
      this.info.isshow = e;
    },
    edit(id) {
      this.$emit("edit",id);
    },
    del(id) {
      this.$confirm("你确定要删除当前这条数据吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //调用删除接口
          menuDel({ id }).then((res) => {
          this.getMenulist()

            if (res.code == 200) {
              //删除成功，要重新调用接口列表
              menuList().then((res) => {
                console.log(res, "菜单列表");
                if (res.code == 200) {
                  this.tableData = res.list;
                  console.log(111);
                }
              });
              this.$message.success(res.msg);
            } else {
              this.$message.error(res.msg);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>

<style scoped>
.el-menu {
  margin: -20px;
  margin-bottom: 20px;
}
</style>